﻿
using Knlght.Domain;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Knight.Models.Entity
{
    /// <summary>
    /// 通用栏目信息表
    /// </summary>
    public class SinglePageInfo : TEntityBase
    {
        /// <summary>
        /// 主键ID----nextId
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 父级Id
        /// </summary>
        public int PId { get; set; }

        /// <summary>
        /// 标题
        /// </summary>
        public string Title { get; set; }

        /// <summary>
        /// 跳转链接
        /// </summary>
        public string JumpLink { get; set; }

        /// <summary>
        /// 打开新窗口
        /// </summary>
        public bool IsBlank { get; set; }
        /// <summary>
        /// 内容
        /// </summary>
        public string Content { get; set; }

        /// <summary>
        /// 排序(数字从小到大排序)
        /// </summary>
        public int DisplayIndex { get; set; }

        /// <summary>
        /// 点击数
        /// </summary>
        public int Hit { get; set; }

        /// <summary>
        /// 是否启用
        /// </summary>
        public bool IsEnabled { get; set; }

        /// <summary>
        /// 添加时间
        /// </summary>
        public DateTime AddTime { get; set; }

        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime UpdateTime { get; set; } = DateTime.Now;
    }

    public class SinglePageInfoMapping : EntityTypeConfiguration<SinglePageInfo>
    {
        public SinglePageInfoMapping()
        {
            // 设置表名
            this.ToTable("T" + nameof(SinglePageInfo));
            //设置主键
            this.HasKey(a => a.Id);
            this.Property(a => a.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
            //不更新
            this.Property(a => a.AddTime).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);
            // 设置属性的类型和长度
            this.Property(a => a.Title).HasColumnType("NVarchar").HasMaxLength(300);
            this.Property(a => a.Content).HasColumnType("ntext");
        }
    }
}
